package com.pdg.mcplugin.ranger.dataproviders;

import com.pdg.mcplugin.common.baseclasses.DataProviderBase;
import com.pdg.mcplugin.common.interfaces.TableProviderKey;

public class PlaceNameKey implements TableProviderKey{
	public static final String FIELD_PLAYER = "player";
	public static final String FIELD_PLACE_NAME = "place_name";
	public static final String FIELD_WORLD = "world";
	private static final String CREATE_FIELDS = "`"+
			FIELD_PLAYER+"` TEXT NOT NULL,`"+
			FIELD_PLACE_NAME+"` TEXT NOT NULL,`"+
			FIELD_WORLD+"` TEXT NOT NULL";
	private static final String INSERT_FIELDS = "`"+
			FIELD_PLAYER+"`,`"+
			FIELD_PLACE_NAME+"`,`"+
			FIELD_WORLD+"`";
	private static final String INSERT_VALUES_FORMAT = "'%s','%s','%s'";
	private static final String WHERE_CLAUSE_FORMAT = "`"+
			FIELD_PLAYER+"`='%s' AND  `"+
			FIELD_PLACE_NAME+"`='%s' AND  `"+
			FIELD_WORLD+"`='%s'";

	private String player;
	private String placeName;
	private String world;
	
	public PlaceNameKey(String thePlayer,String thePlaceName,String theWorld){
		setPlayer(thePlayer);
		setPlaceName(thePlaceName);
		setWorld(theWorld);
	}

	private void setWorld(String theWorld) {
		world = theWorld;
	}

	private void setPlaceName(String thePlaceName) {
		placeName = thePlaceName;
	}

	private void setPlayer(String thePlayer) {
		player = thePlayer;
	}

	public String getPlayer() {
		return player;
	}

	public String getPlaceName() {
		return placeName;
	}

	public String getWorld() {
		return world;
	}

	@Override
	public String getCreateFields() {
		return CREATE_FIELDS;
	}

	@Override
	public String getInsertFields() {
		return INSERT_FIELDS;
	}

	@Override
	public String getInsertValues() {
		return String.format(INSERT_VALUES_FORMAT, DataProviderBase.sqlSafeString(getPlayer()),DataProviderBase.sqlSafeString(getPlaceName()),DataProviderBase.sqlSafeString(getWorld()));
	}

	@Override
	public String getWhereClause() {
		return String.format(WHERE_CLAUSE_FORMAT, DataProviderBase.sqlSafeString(getPlayer()),DataProviderBase.sqlSafeString(getPlaceName()),DataProviderBase.sqlSafeString(getWorld()));
	}

}
